<template>
<div class="header">
<!--  折叠图片-->
  <div class="collapse-btn" @click="changeCollapse">
    <i class="el-icon-menu"></i>
  </div>
  <div class="logo">BuleHeart后台管理平台</div>
  <div class="header-right">
    <div class="btn-fullscreen" @click="handleFullScreen">
      <el-tooltip :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
        <i class="el-icon-rank"></i>
      </el-tooltip>
    </div>
<!--    用户头像-->
    <div class="user-avator">
      <img src="../assets/img/1.png">
    </div>
<!--    下拉菜单-->
    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
         <span class="el-dropdown-link">
           {{getName}}
           <i class="el-icon-caret-bottom"></i>
         </span>
      <el-dropdown-menu slot="dropdown">
       <el-dropdown-item command="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</div>
</template>

<script>
export default {
  name: "Header",
  data(){
    return{
      collapse:false,
      fullscreen:false
    }
  },
  methods:{
    //菜单栏折叠
    changeCollapse(){
      this.collapse=!this.collapse
      this.$bus.$emit('collapse',this.collapse)
    },
    //全屏事件
    handleFullScreen(){
      if (this.fullscreen){
        if (document.exitFullscreen){
          document.exitFullscreen()
        //  safari,谷歌
        }else if (document.webkitCancelFullScreen){
         document.webkitCancelFullScreen()
          //火狐
        }else if (document.mozCancelFullScreen){
          document.mozCancelFullScreen()
          //ie
        }else if (document.msExitFullScreen){
          document.msExitFullScreen()
        }
      }else {
        let element = document.documentElement;
        if (element.requestFullscreen){
          element.requestFullscreen()
        }else if (element.webkitRequestFullScreen){
          element.webkitRequestFullScreen()
        }else if (element.mozRequestFullScreen){
          element.mozRequestFullScreen()
        }else if (element.msRequestFullScreen){
          element.msRequestFullScreen()
        }
      }
      this.fullscreen=!this.fullscreen
    },
    //下拉菜单
    handleCommand(command){
      if (command=="logout"){
        this.$API.reqLogoutByAdmin()
        localStorage.removeItem('name')
        localStorage.removeItem('uuid')
        this.$router.push('login')
      }
    }
  },
  computed:{
    getName(){
      return localStorage.getItem('name')
    }
  }
}
</script>

<style scoped>
.header{
  position: relative;
  background-color: #253041;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  color: white;
}
.collapse-btn{
  float: left;
  padding: 0 21px;
  cursor: pointer;
  line-height: 70px;
}
.header .logo{
  position: relative;
  float: left;
  line-height: 70px;
}
.header-right{
  position: relative;
  float: right;
  padding-right:50px;
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen{
  margin-right: 5px;
  font-size: 24px;
  transform: rotate(45deg);
}
.user-avator{
  margin-left: 20px;
}
.user-avator  img{
  display: flex;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.user-name{
  margin-left: 10px;
}
.el-dropdown-link{
  color: white;
  cursor: pointer;
}
</style>
